*****************************************************************************************************************************************************
* PROJECT: 		Exposure to the COVID-19 Stock Market Crash and its Effect on Household Expectations
* DATE: 		Nov 2020
* CONTENT: 		FIGURES
* AUTHORS: 		Tobin Hanspal, Johannes Wohlfart, Anni Weber
*****************************************************************************************************************************************************

		clear all
		set scheme lean2
		global pm = char(177)
		set more off
		gl date = c(current_date)
		graph set window fontface "cmr10"
		
		
* set cd as /Replication_files_HanspalWeberWohlfart2020/

*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~						
** FIGURE A21
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~										

use data/processed/data_1, clear

gen riskshare_retirwealth_Jan201=riskshare_retirwealth_Jan20
gen riskshare_ofinwealth_Jan201=riskshare_ofinwealth_Jan20
replace riskshare_retirwealth_Jan201=0 if retirJan20_0==1
replace riskshare_ofinwealth_Jan201=0 if ofinJan20_0==1
gen stockinvestor_retire=riskshare_retirwealth_Jan201>0 if riskshare_retirwealth_Jan201!=.
gen stockinvestor_ofin=riskshare_ofinwealth_Jan201>0 if riskshare_ofinwealth_Jan201!=.
gen delhhnetinc_USD_tr02alt_qtr_cond = delhhnetinc_USD_tr02alt_qtr if jobloss_20q1==1
gen del_hhnetinc_perc_tr02_cond = del_hhnetinc_perc_tr02 if jobloss_20q1==1
	
* Scale USD variables	
	foreach x in  delofin_USD_tr02 delretir_USD_tr02  delfinwealth_USD_tr02   delhhnetinc_USD_tr02  delofin_USD_tr02alt delretir_USD_tr02alt  delfinwealth_USD_tr02alt {
		replace `x' = `x'/1000
	}
	foreach x in ofinwealth_lvl retirewealth_lvl  finwealth_Jan20 hhinc_lvl hhnetinc_2019   {
		replace `x' = `x'/1000
	}

* gen conditional variables:
	gen del_ofin_perc_tr02_cond = del_ofin_perc_tr02
	replace del_ofin_perc_tr02_cond = . if stockinvestor_ofin!=1
	gen del_retir_perc_tr02_cond = del_retir_perc_tr02
	replace del_retir_perc_tr02_cond = . if stockinvestor_retire!=1
	gen del_finwealth_perc_tr02_cond = del_finwealth_perc_tr02
	replace del_finwealth_perc_tr02_cond = . if stockowner!=1

	gen delofin_USD_tr02_cond = delofin_USD_tr02
	replace delofin_USD_tr02_cond = . if stockinvestor_ofin!=1
	gen delretir_USD_tr02_cond = delretir_USD_tr02
	replace delretir_USD_tr02_cond = . if stockinvestor_retire!=1
	gen delfinwealth_USD_tr02_cond = delfinwealth_USD_tr02
	replace delfinwealth_USD_tr02_cond = . if stockowner!=1

* gen extensive margin vars:
	gen del_ofin_d = (del_ofin_perc_tr02<0) if  del_ofin_perc_tr02!=. 
	replace del_ofin_d = . if stockinvestor_ofin!=1
	
	gen del_retire_d = (del_retir_perc_tr02<0) if  del_retir_perc_tr02!=. 
	replace del_retire_d = . if stockinvestor_retire!=1
	
	gen del_finwealth_d = (del_finwealth_perc_tr02<0) if  del_finwealth_perc_tr02!=. 
	replace del_finwealth_d = . if stockowner!=1
	
	gen riskshare_5 = .
	replace riskshare_5=1 if riskshare_finwealth_Jan201>=0 &riskshare_finwealth_Jan201<=20 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=2 if riskshare_finwealth_Jan201>20 &riskshare_finwealth_Jan201<=40 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=3 if riskshare_finwealth_Jan201>40 &riskshare_finwealth_Jan201<=60 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=4 if riskshare_finwealth_Jan201>60 &riskshare_finwealth_Jan201<=80 & riskshare_finwealth_Jan201!=.
	replace riskshare_5=5 if riskshare_finwealth_Jan201>80 &riskshare_finwealth_Jan201<=100 & riskshare_finwealth_Jan201!=.


	keep if finwealth_Jan20>0

* CHANGE IN FINANCAIAL WEALTH  
  
  * change in fin wealth by netwealth
	graph bar (mean)  del_ofin_perc_tr02 del_retir_perc_tr02   del_finwealth_perc_tr02  , ///
		over(netwealth_Jan20_grp, relabel(1 1 2 2 3 3 4 4 5 5)) b1title() ///
		  bargap(0)  /// 
		ytitle("%", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-20(5)0, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp1.gph, replace)
		
 * change in fin wealth by age	
	graph bar (mean) del_ofin_perc_tr02 del_retir_perc_tr02   del_finwealth_perc_tr02 , ///
		over(agecat, relabel(1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+") label(labsize(small))) b1title() ///
		  bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-20(5)0, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp2.gph, replace)
	
* change in fin wealth by hh net income		
	graph bar (mean)  del_ofin_perc_tr02 del_retir_perc_tr02   del_finwealth_perc_tr02 , ///
		over(hhnetinc_2019_grp) b1title() ///
		  bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-20(5)0, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/temp3.gph, replace)

  * change in fin wealth by netwealth
	graph bar (mean) delofin_USD_tr02alt delretir_USD_tr02alt  delfinwealth_USD_tr02alt ,  ///
		over(netwealth_Jan20_grp, relabel(1 1 2 2 3 3 4 4 5 5))  b1title(Net wealth quintile, size(medsmall)) /// 
		  bargap(0)  /// 
		ytitle("$1000", size(medsmall)) ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-120(20)0, nogrid)  legend(size(small) symxsize(3) symysize(3)  pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/tempd1.gph, replace)

	*change in fin wealth by age
	graph bar (mean)  delofin_USD_tr02alt delretir_USD_tr02alt  delfinwealth_USD_tr02alt , ///
		over(agecat, relabel(1 "18-24" 2 "25-34" 3 "35-44" 4 "45-54" 5 "55-64" 6 "65+") label(labsize(small))) b1title(Age group, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-120(20)0, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/tempd2.gph, replace)
	
  * change in fin wealth by net income
	graph bar (mean) delofin_USD_tr02alt delretir_USD_tr02alt  delfinwealth_USD_tr02alt , ///
		over(hhnetinc_2019_grp) b1title(Net income quintile, size(medsmall)) ///
		  bargap(0)  /// 
		ytitle("") ///
		yline(0, lcolor(gs8) lpattern(dash)) graphregion(color(white)) bgcolor(white) ///
		ylabel(-120(20)0, nogrid)  legend(size(small) pos(6) ring(1) cols(6) ///
		label(1 "Other financial wealth") label(2 "Retirement wealth") ///
		label(3 "Total financial wealth")) saving(Figures/tempd3.gph, replace)

	grc1leg2 		Figures/temp1.gph ///
					Figures/temp3.gph ///
					Figures/temp2.gph ///
					Figures/tempd1.gph ///
					Figures/tempd3.gph ///
					Figures/tempd2.gph ///
					, cols(3) rows(2) ysize(2) xsize(4) ///
					ring(1) pos(6) legendfrom(Figures/temp1.gph) ///
					l1title("Change in financial wealth", size(small)) ///
					saving(Figures/tempx.gph, replace) imargin(.1)
					
	graph export Figures/FigureA21.pdf, as(pdf)  fontface("cmr10") replace							
	graph export Figures/FigureA21.png,  width(1600) replace			
	
	forvalues x = 1/3 {
		capture erase Figures/temp`x'.gph
		capture erase Figures/tempd`x'.gph
}						
	capture erase Figures/tempx.gph								
